using System;
using System.Collections;
using System.Data.Linq.Mapping;
using System.Runtime.Serialization;
using Portal.Data.Helper;
using Portal.Core.Binding.FormBuilder;
using Portal.Core.Helper;
using System.Linq;

namespace Portal.Data.Entity
{
	[Table(Name = "dbo.Layout"),Serializable, DataContractAttribute]
    public class Layout : BaseObject
	{
		#region Properties
        public int ID { get { return Layout_ID; } set { Layout_ID = value; } }

        [SkipBinding]
		[ColumnAttribute(Name = "Layout_ID", IsPrimaryKey = true , IsDbGenerated = true)]
        public int Layout_ID { get; set; }

        [ColumnAttribute(Name = "Name"), Validator(Required = true), Unique]
		public string Name {get;set;}

        [ColumnAttribute(Name = "Path"), Validator(Required = true)]
		public string Path {get;set;}

		[ColumnAttribute(Name = "DefaultZone")]
		public string DefaultZone {get;set;}

        [ColumnAttribute(Name = "Icon"), Builder(DataType = DataType.Image), Image(SavePath = "Images/Layout/")]
		public string Icon {get;set;}


		#endregion

		#region Methods
		public static Layout FindByPrimaryKey(object objectid)
		{
		    return FindByPrimaryKey<Layout>(objectid);
		}
        public static IList ListAll()
        {
            //getcache  -----------------------
            var parameter = new object[] { typeof(Layout).Name, "ListAll" };
            var obj = CacheHelper.Instance.Get(parameter);
            if (obj != null)
                return (IList)obj;
            //end get cache -------------------
            var value = LINQHelper.GetList<Layout>("select * from Layout");
            CacheHelper.Instance.Set(parameter, value);
            return value;
        }
        public static Layout GetFirst()
        {
            //getcache  -----------------------
            var parameter = new object[] { typeof(Layout).Name, "GetFirst" };
            var obj = CacheHelper.Instance.Get(parameter);
            if (obj == null)
            {
                var result = LINQHelper.GetFirst<Layout>("select top 1 * from Layout");
                CacheHelper.Instance.Set(parameter, result);
                return result;
            }
            return (Layout)obj;
        }

        public static Portal.Core.Web.UI.WebLayout LoadLayout(System.Web.UI.Page page, string layoutPath)
        {
            var layout = (Portal.Core.Web.UI.WebLayout)page.LoadControl(layoutPath);
            return layout;
        }
		#endregion Methods

	}
}
